package com.milhouz.quizzdroid.bean;

import android.os.Parcel;
import android.os.Parcelable;

public class Score implements Parcelable {

	int nbQuestions = 0;
	int nbCorrectResponses = 0;
	float meanTimeResponseMs = 0;

	public void addNbQuestions() {
		nbQuestions++;
	}

	public void addCorrectResponses() {
		nbCorrectResponses++;
	}

	public int getNbQuestions() {
		return nbQuestions;
	}

	public int getNbCorrectResponses() {
		return nbCorrectResponses;
	}

	public float getMeanTimeResponseMs() {
		return meanTimeResponseMs;
	}

	public float getMeanTimeResponseSec() {
		return meanTimeResponseMs / 1000;
	}

	public void addResponseTime(final float responseTime) {
		if (meanTimeResponseMs == 0) {
			meanTimeResponseMs = responseTime;
		} else {
			meanTimeResponseMs = (meanTimeResponseMs + responseTime) / 2;
		}
	}

	@Override
	public void writeToParcel(Parcel parcel, int flags) {
		parcel.writeInt(nbQuestions);
		parcel.writeInt(nbCorrectResponses);
		parcel.writeFloat(meanTimeResponseMs);
	}

	public static final Creator<Score> CREATOR = new Creator<Score>() {
		@Override
		public Score createFromParcel(Parcel source) {
			Score s = new Score();
			s.nbQuestions = source.readInt();
			s.nbCorrectResponses = source.readInt();
			s.meanTimeResponseMs = source.readFloat();
			return s;
		}

		@Override
		public Score[] newArray(int arg0) {
			return null;
		}
	};

	@Override
	public int describeContents() {
		return 0;
	}

}
